//
//  MineInfoView.m
//  WeCommunity
//
//  Created by mac on 2017/6/15.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "MineInfoView.h"


@implementation MineInfoView


-(void)reloadWithData
{
    self.listArray = [NSMutableArray array];
    
    NSArray * detailArray = @[self.contact.headImage,self.contact.nickName,self.contact.WXUserName,self.contact.sexString];
    NSArray * titleArray = @[@"headImageTitle",@"nameTitle",@"WXName",@"Sex"];
    
    for (int i = 0 ; i < detailArray.count; i++) {
        MineContentListModel * content = [MineContentListModel new];
        content.detail = detailArray[i];
        content.contentName = KNSLocal(titleArray[i]);
        if (i == 0) {
            [self.listArray addObject:@"0"];
            content.mark = 0;
            [self.listArray addObject:content];
            [self.listArray addObject:@"1"]; //加一些其他数据进去;
        }else{
            content.mark = 1;
            [self.listArray addObject:content];
        }
    }
    
    [self.tableView reloadData];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id object = self.listArray[indexPath.row];
    
    if ([object isKindOfClass:[NSString class]]) {
        if ([(NSString *)object isEqualToString:@"0"]) {
            return NULL_ROW1_Height;
        }else if ([(NSString *)object isEqualToString:@"1"]){
            return NULL_ROW2_Height;
        }
    }else if ([object isKindOfClass:[MineContentListModel class]]) {
        if (((MineContentListModel *)object).mark == 0) {
            return Row1_Height;
        }else if (((MineContentListModel *)object).mark == 1){
            return Row2_Height;
        }
    }
    return 0;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    MineListSpaceCell
    id object = self.listArray[indexPath.row];
    
    if ([object isKindOfClass:[NSString class]]) {
        //隔行cell
        static NSString * cellID = @"mineListSpaceCell";
        MineListSpaceCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell =[[MineListSpaceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        //没有点击效果
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else if ([object isKindOfClass:[MineContentListModel class]]) {
        static NSString * cellID = @"mineList2Cell";
        MineContentListCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell =[[MineContentListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        [cell showMineInfoCellWithModel:object];
        if (indexPath.row == 1) {
            [cell needAddTopLine:YES addBottomLine:YES];
        }else if (indexPath.row == 3) {
            [cell needAddTopLine:YES addBottomLine:NO];
        }else if(indexPath.row == self.listArray.count - 1){
            [cell needAddTopLine:NO addBottomLine:YES];
        }else{
            [cell needAddTopLine:NO addBottomLine:NO];
        }
        return cell;
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id object = self.listArray[indexPath.row];
    if ([object isKindOfClass:[NSString class]]) {
        return;
    }
    
    NSInteger index = 0;
    if (indexPath.row == 1) {
        index = 0;
    }else if (indexPath.row >= 3 && indexPath.row <= 5) {
        index = indexPath.row - 2;
    }
    
    if (self.delegate) {
        [self.delegate mineCotentListViewSelectRowAtIndex:index];
    }
}

@end
